package com.girlbook.controllers;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.portal.Portal;
import net.paoding.rose.web.var.Flash;

import org.springframework.beans.factory.annotation.Autowired;

import com.girlbook.bean.Chen;
import com.girlbook.bean.NotBlank;
import com.girlbook.bean.User;
import com.girlbook.model.Test;
import com.girlbook.service.TestService;

/**
 * ROOT的下级有个GET结点，
 * 代表对该地址支持GET访问， 不支持POST等其它访问，
 * 如果进行POST访问将以405错误回应。
 */
@Path("")
public class HelloController
{
	@Autowired
	private TestService tService;

	
	@Get("whuface")
	public String whuface() throws Exception
	{
		return "whuface/index";
	}
	
	@Get("photodesk")
	public String photodesk() throws Exception
	{
		return "photodesk";
	}
	
	@Get("g+")
	public String gplus() throws Exception
	{
		return "gplus";
	}

	@Get("/hello")
	public String index() throws Exception
	{
		Test t = tService.getTest();
		return "@hello world:" + t.getId()+"-----"+t.getMsg();
	}

	@Get("/param")
	public String param(Chen chen) throws Exception
	{
		return "@hello world:" + chen.getChen1() + ":" + chen.getChen2();
	}

	@Get("/user")
	public String post(User user)
	{
		return "@" + user.getId() + "; level=" + user.getLevel() + "; name="
				+ user.getName();
	}

	@Get("/notBlank")
	public String notBlank(@NotBlank @Param("messages") String messages)
			throws Exception
	{
		return "@hello world";
	}

	@Get("/flash1")
	public String flashStep1(Flash flash)
	{
		flash.add("msg", "-----修改成功！-----");
		return "r:/flash2";
	}

	@Get("/flash2")
	public String flashStep2(Invocation inv, Flash flash)
	{
		inv.addModel("info", flash.get("msg"));
		return "flash";
	}

	@Get("/3.7")
	public String portal(Portal portal)
	{
		portal.addWindow("p1", "/wp1");
		portal.addWindow("p2", "/wp2");
		return "portal";
	}

	@Get("/wp1")
	public String portal1()
	{
		return "@this is p1";
	}

	@Get("/wp2")
	public String portal2()
	{
		return "@this is p2";
	}
	
	@Get("/gallery")
	public String gallery()
	{
		return "gallery";
	}
	
	@Get("/ueditor")
	public String ueditor()
	{
		return "ueditor";
	}
}
